home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: miker3@ix.netcom.com (Mike Rubenstein)
- Newsgroups: comp.lang.c
- Subject: Re: start array at k, not 0
- Date: Mon, 08 Jan 1996 01:13:35 GMT
- Organization: Netcom
- Message-ID: <30f06d21.167303296@nntp.ix.netcom.com>
- References: <Pine.OSF.3.91.960104095358.22268B-100000@io.UWinnipeg.ca> <820787486snz@genesis.demon.co.uk> <Pine.OSF.3.91.960105091211.2861B-100000@io.UWinnipeg.ca> <4cpdt3$3b5@newdelph.cig.mot.com>
- NNTP-Posting-Host: ix-dc14-09.ix.netcom.com
- X-NETCOM-Date: Sun Jan 07 5:13:38 PM PST 1996
- X-Newsreader: Forte Agent .99c/16.141
-
- "John R. Haug" <Haug_John@pcsmail.cig.mot.com> wrote:
-
- |>I don't know if anyone else mentioned this, since I am just starting
- to
- |>read this newsgroup, but the book, "Numerical Recipes in C: The Art
- of
- |>Scientific Computing" published by Cambridge University Press
- describes
- |>a great way of doing what I think you are looking for. As a C and
- |>FORTRAN programmer, I use their techniques extensively when writing
- |>scientific code in C.
-
- I don't think anyone has mentioned this yet on this thread.
-
- Perhaps the reason is that the method proposed in that book is
- incorrect and results in undefined behavior. I'd suggest you stop
- using it and stick to correct C.
-
- For those not acquainted with the book, the authors recommend:
-
- One problem is that many algorithms naturally like to go from
- 1 to M, not from 0 to M - 1. Sure, you can always convert
- them, but they often acquire a baggage of additional
- arithmetic in array indices that is, at best, distracting. It
-
- is better to use the power of the C language, in a consistent
- way, to make the problem disappear. Consider
-
- float b[4], *bb;
- bb = b - 1;
-
- The pointer bb now points one location before b. A
- consequence is that the array elements bb[1], bb[2], bb[3],
- and bb[4] all exist. In other words the range of bb is
- bb[1..4]. We wil refer to bb as a unit-offset vector.
-
- It's unfortunate that the authors of this book didn't bother to learn
- C before writing it. As anyone who has read the FAQ [6.13] knows,
- this results in undefined behavior. The program is under no
- obligation to do anything sensible if you code like this.
-
-
- Michael M Rubenstein
-